<template>
    <div>{{ text }}</div>
</template>
<script>
import * as CryptoJS from "crypto-js";
import user from "@/store/modules/user";

export default {
    data() {
        return {
            text: "跳转中",
        }
    },
    mounted() {
       this.$nextTick(() => {
           this.init()
       })
    },

    methods: {
        init() {
            // 解析url
            // let url = decodeURIComponent(this.$route.query.url);
            // if(!url){
             let  url = process.env.VUE_APP_IPQC_URL;
            // }
            const encryptedText = this.encrypt(
                user.state.loginName,
                "1234567890adbcde",
                "1234567890hjlkew"
            );
            const tempObj = {
                username: encodeURIComponent(encryptedText),
                source: "IQC",
            };
            const objToQuery = (obj) => {
                let query = "";
                for (let key in obj) {
                    query += `${key}=${obj[key]}&`;
                }
                return query.slice(0, -1);
            };
            this.text = "已跳转";
            window.open(`${url}?${objToQuery(tempObj)}`);
            // this.$router.back()
        },
        encrypt(data, key, iv) {
            //编码 key
            key = CryptoJS.enc.Utf8.parse(key);
            //编码iv
            iv = CryptoJS.enc.Utf8.parse(iv);
            //编码data
            data = CryptoJS.enc.Utf8.parse(data);
            // 加密模式为CBC，补码方式为NoPadding，位数为128
            let encrypted = CryptoJS.AES.encrypt(data, key, {
                iv: iv,
                mode: CryptoJS.mode.CBC,
                padding: CryptoJS.pad.ZeroPadding,
            });
            console.log("加密后的数据:", CryptoJS.enc.Base64.stringify(encrypted.ciphertext));
            //返回base64
            return CryptoJS.enc.Base64.stringify(encrypted.ciphertext);
        }
    },
}
</script>